package cn.edu.seig.textbook.controller;


import cn.edu.seig.textbook.domain.pojo.Textbooks;
import cn.edu.seig.textbook.service.ITeachersService;
import cn.edu.seig.textbook.service.ITextbooksService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author day
 * @since 2024-11-07
 */
@Controller
@RequestMapping("/teacher")
public class TeachersController {

    @Autowired
    ITeachersService teachersService;
    @Autowired
    ITextbooksService textbooksService;
    //教师首页
    @RequestMapping("/toTeacher")
    public String toTeacher(Model model, @AuthenticationPrincipal UserDetails userDetails, HttpSession session) {
        session.setAttribute("userDetails", userDetails);
        return "teacher/teacher";}


    @RequestMapping("/textbook_all")
    public String textbookAll(HttpServletRequest request) {
        List<Textbooks> textbooks=textbooksService.getAllTestbooks();
        request.setAttribute("textbooks", textbooks);
        return "teacher/showAllTextbook";
    }

    @RequestMapping("/findBookName")
    public String findBookName(HttpServletRequest request,@Param("bookName") String bookName){
        List<Textbooks> textbooks=textbooksService.getTextbooksByBookName(bookName);
        request.setAttribute("textbooks", textbooks);
        return "teacher/showAllTextbook";}

}
